home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Utilities.c
-
- Contains: A Sample application for dictionary access.
-
- Version: Technology: System 8
- Release: Daruma Developer Release 1
-
- Copyright: 1998 by Apple Computer, Inc., all rights reserved
-
- Contact: daruma@apple.com
-
- */
-
-
- #include "DictionaryAccess.h"
- #include "FunctionProto.h"
-
- #include <Windows.h>
- #include <TextUtils.h>
- #include <string.h>
- #include <Memory.h>
- #include <Appearance.h>
- #include <Lists.h>
- #include <OSUtils.h>
-
-
- //========================================================================================
- // GetDialogEditTextItemString
- //========================================================================================
- void GetDialogEditTextItemString( DialogPtr dialog, SInt16 item, Str255 string)
- {
- OSStatus err;
- Size actualSize;
- ControlHandle controlHandle;
-
- err = GetDialogItemAsControl( dialog, item, &controlHandle);
-
- if ( err == noErr )
- {
- GetControlData( controlHandle, (ControlPartCode)0, kControlEditTextTextTag, 255, (Ptr)&string[1], &actualSize);
- string[0] = actualSize;
- }
- }
-
-
- //========================================================================================
- // SetDialogEditTextItemString
- //========================================================================================
- void SetDialogEditTextItemString( DialogPtr dialog, SInt16 item, ConstStr255Param string)
- {
- OSStatus err;
- ControlHandle controlHandle;
-
- err = GetDialogItemAsControl( dialog, item, &controlHandle);
-
- if ( err == noErr )
- {
- SetControlData( controlHandle, (ControlPartCode)0, kControlEditTextTextTag, string[0], (Ptr)&string[1]);
- DrawOneControl( controlHandle);
- }
- }
-
-
- //========================================================================================
- // GetDialogStaticTextItemString
- //========================================================================================
- void GetDialogStaticTextItemString( DialogPtr dialog, SInt16 item, Str255 string)
- {
- OSStatus err;
- Size actualSize;
- ControlHandle controlHandle;
-
- err = GetDialogItemAsControl( dialog, item, &controlHandle);
-
- if ( err == noErr )
- {
- GetControlData( controlHandle, (ControlPartCode)0, kControlStaticTextTextTag, 255, (Ptr)&string[1], &actualSize);
- string[0] = actualSize;
- }
- }
-
-
- //========================================================================================
- // SetDialogStaticTextItemString
- //========================================================================================
- void SetDialogStaticTextItemString( DialogPtr dialog, SInt16 item, ConstStr255Param string)
- {
- OSStatus err;
- ControlHandle controlHandle;
-
- err = GetDialogItemAsControl( dialog, item, &controlHandle);
-
- if ( err == noErr )
- {
- SetControlData( controlHandle, (ControlPartCode)0, kControlStaticTextTextTag, string[0], (Ptr)&string[1]);
- DrawOneControl( controlHandle);
- }
- }
-
-
- //========================================================================================
- // SelectDialogEditTextItemString
- //========================================================================================
- void SelectDialogEditTextItemString( DialogPtr dialog, SInt16 item, SInt16 start, SInt16 end)
- {
- OSStatus err;
- ControlHandle controlHandle;
- ControlEditTextSelectionRec selection;
-
- err = GetDialogItemAsControl( dialog, item, &controlHandle);
-
- if ( err == noErr )
- {
- selection.selStart = start;
- selection.selEnd = end;
-
- SetControlData( controlHandle, (ControlPartCode)0, kControlEditTextSelectionTag, sizeof( selection), (Ptr)&selection);
- DrawOneControl( controlHandle);
- }
- }
-
-
- //========================================================================================
- // HiliteButtonDialogItem
- //========================================================================================
- void HiliteButtonDialogItem( DialogPtr dialog, SInt16 item)
- {
- OSStatus err;
- ControlHandle controlHandle;
-
- err = GetDialogItemAsControl( dialog, item, &controlHandle);
-
- if ( err == noErr && IsControlActive( controlHandle) )
- {
- UInt32 finalTicks;
-
- HiliteControl( controlHandle, kControlButtonPart);
- Delay( 10, &finalTicks);
- HiliteControl( controlHandle, 0);
- }
- }
-
-
- // ========================================================================================
- // GetListHandleFromControl
- // ========================================================================================
- ListHandle GetListHandleFromControl( ControlHandle controlHandle )
- {
- OSStatus err;
- ListHandle listHandle;
- Size actualSize;
-
- err = GetControlData( controlHandle, (ControlPartCode)0, kControlListBoxListHandleTag, sizeof(listHandle), (Ptr)&listHandle, &actualSize);
- if ( err != noErr ) listHandle = NULL;
-
- return listHandle;
- }
-
-
- // ========================================================================================
- // PascalStrToCStr
- // ========================================================================================
- char *PascalStrToCStr ( StringPtr pStr )
- {
- long len = (long)pStr[0];
-
- BlockMoveData( &pStr[1], &pStr[0], len);
- pStr[len] = '\0';
-
- return (char *)&pStr[0];
- }
-
-
- // ========================================================================================
- // CStrToPascalStr
- // ========================================================================================
- StringPtr CStrToPascalStr ( char *cStr )
- {
- long len = strlen( cStr);
-
- BlockMoveData( &cStr[0], &cStr[1], len);
- cStr[0] = len;
-
- return (StringPtr)&cStr[0];
- }
-
-
-
-
-